package com.bonc.rms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.bonc.rms.service.PetInfoService;

@RestController
@RequestMapping(value = "/petInfoController")
public class PetInfoController {
	@Autowired
	PetInfoService petInfoService;
	
	/*
	 * 查看宠物信息
	 */
	@RequestMapping(value = "/getPetInfo")
	@ResponseBody
	public String getPetInfo() {
		
		List<Map<String, Object>> petInfo = petInfoService.getPetInfo();
		
		return JSON.toJSONString(petInfo);
	}
	
	/*
	 * 查看单个宠物信息
	 */
	@RequestMapping(value = "/getSinglePetInfo")
	@ResponseBody
	public String getSinglePetInfo(@RequestParam(value = "petId") Integer petId) {
		
		List<Map<String, Object>> petInfo = petInfoService.getSinglePetInfo(petId);
		
		return JSON.toJSONString(petInfo);
	}

	/*
	 * 修改宠物信息
	 */
	@RequestMapping(value = "/updatePetInfo")
	@ResponseBody
	public String updatePetInfo(@RequestParam(value = "petId") Integer petId,
			@RequestParam(value = "petNumber") String petNumber,
			@RequestParam(value = "petName") String petName,
			@RequestParam(value = "pic") String pic,
			@RequestParam(value = "sex") String sex,
			@RequestParam(value = "age") String age,
			@RequestParam(value = "size") String size,
			@RequestParam(value = "variety") String variety,
			@RequestParam(value = "character") String character,
			@RequestParam(value = "price") String price) {
		
		List<Map<String, Object>> petInfo = petInfoService.updatePetInfo(petId,petNumber,petName,pic,sex,age,size,variety,character,price);
		
		return JSON.toJSONString(petInfo);
	}
	
	/*
	 * 删除宠物信息
	 */
	@RequestMapping(value = "/deletePetInfo")
	@ResponseBody
	public String deletePetInfo(@RequestParam(value = "petId") Integer petId) {
		
		petInfoService.deletePetInfo(petId);
		
		Map<Object,Integer> map = new HashMap<>();
		map.put("status", 200);
		return JSON.toJSONString(map);
	}
	
	/*
	 * 增加宠物信息
	 */
	@RequestMapping(value = "/addPetInfo")
	@ResponseBody
	public String addPetInfo(@RequestParam(value = "petId") Integer petId,
			@RequestParam(value = "petName") String petName,
			@RequestParam(value = "pic") String pic,
			@RequestParam(value = "sex") String sex,
			@RequestParam(value = "age") String age,
			@RequestParam(value = "size") String size,
			@RequestParam(value = "variety") String variety,
			@RequestParam(value = "character") String character,
			@RequestParam(value = "price") String price) {
		List<Map<String, Object>> petInfo = petInfoService.addPetInfo(petId,petName,pic,sex,age,size,variety,character,price);
		
		return JSON.toJSONString(petInfo);
	}
	

}
